package com.hyc.algorithm.tree.Search;

import com.hyc.algorithm.Node.TreeNode;

/**
 * @projectName: DataStructure
 * @package: com.hyc.algorithm.tree.Search
 * @className: binaryTreeDfs
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/4/4 17:04
 * @version: 1.0
 */
public class binaryTreeDfs {
    public static void main(String[] args) {
        TreeNode node1 = new TreeNode(1);
        TreeNode node2 = new TreeNode(2);
        TreeNode node3 = new TreeNode(3);
        TreeNode node4 = new TreeNode(4);
        TreeNode node5 = new TreeNode(5);
        TreeNode node6 = new TreeNode(6);
        node1.left = node2;
        node1.right = node3;
        node2.left = node4;
        node3.right = node5;
        node3.right = node6;
        System.out.println(dfs(node1, 3));
    }

    public static boolean dfs(TreeNode root, int target) {
        if (root == null) {
            return false;
        }
        if (root.val == target) {
            return true;
        }
        return dfs(root.left, target) || dfs(root.right, target);
    }

}
